home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1994 February: Tool Chest / Dev.CD Feb 94.toast / Tool Chest / Development Platforms / AppsToGo / AppsToGo.src / FontTester / WSTGS.c < prev   
Encoding:
C/C++ Source or Header  |  1993-06-18  |  5.4 KB  |  222 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        WSTGS.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1993 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* You may incorporate this sample code into your applications without
  12. ** restriction, though the sample code has been provided "AS IS" and the
  13. ** responsibility for its operation is 100% yours.  However, what you are
  14. ** not permitted to do is to redistribute the source as "DSC Sample Code"
  15. ** after having made changes. If you're going to re-distribute the source,
  16. ** we require that you make it clear in the source that the code was
  17. ** descended from Apple Sample Code, but that you've made changes. */
  18.  
  19.  
  20.  
  21. /*****************************************************************************/
  22.  
  23.  
  24.  
  25. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  26. #include "App.defs.h"        /* Get various application definitions.            */
  27. #include "App.protos.h"        /* Get the prototypes for the application.        */
  28.  
  29. #ifndef __ERRORS__
  30. #include <Errors.h>
  31. #endif
  32.  
  33. #ifndef __FONTS__
  34. #include <Fonts.h>
  35. #endif
  36.  
  37. #ifndef __RESOURCES__
  38. #include <Resources.h>
  39. #endif
  40.  
  41. #ifndef __TEXTEDITCONTROL__
  42. #include "TextEditControl.h"
  43. #endif
  44.  
  45. #ifndef __TOOLUTILS__
  46. #include <ToolUtils.h>
  47. #endif
  48.  
  49. #ifndef __UTILITIES__
  50. #include "Utilities.h"
  51. #endif
  52.  
  53.  
  54. /*****************************************************************************/
  55.  
  56.  
  57.  
  58. static void        STGSContentClick(WindowPtr window, EventRecord *event, Boolean firstClick);
  59. static Boolean    STGSContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough);
  60. static OSErr    STGSImageDocument(FileRecHndl frHndl);
  61. static OSErr    STGSInitContent(FileRecHndl frHndl, WindowPtr window);
  62.  
  63.  
  64.  
  65. /*****************************************************************************/
  66. /*****************************************************************************/
  67.  
  68.  
  69.  
  70. OSErr    STGSInitDocument(FileRecHndl frHndl);
  71. OSErr    STGSInitDocument(FileRecHndl frHndl)
  72. {
  73.     FileRecPtr    frPtr;
  74.  
  75.     frPtr = *frHndl;
  76.     frPtr->fileState.calcFrameRgnProc        = nil;
  77.     frPtr->fileState.contentClickProc        = STGSContentClick;
  78.     frPtr->fileState.contentKeyProc          = STGSContentKey;
  79.     frPtr->fileState.drawFrameProc           = nil;
  80.     frPtr->fileState.freeDocumentProc        = nil;
  81.     frPtr->fileState.freeWindowProc          = nil;
  82.     frPtr->fileState.imageProc               = STGSImageDocument;
  83.     frPtr->fileState.initContentProc         = STGSInitContent;
  84.     frPtr->fileState.readDocumentProc        = nil;
  85.     frPtr->fileState.readDocumentHeaderProc  = nil;
  86.     frPtr->fileState.resizeContentProc       = nil;
  87.     frPtr->fileState.scrollFrameProc         = nil;
  88.     frPtr->fileState.undoFixupProc           = nil;
  89.     frPtr->fileState.windowCursorProc        = nil;
  90.     frPtr->fileState.writeDocumentProc       = nil;
  91.     frPtr->fileState.writeDocumentHeaderProc = nil;
  92.  
  93.     return(noErr);
  94. }
  95.  
  96.  
  97.  
  98. /*****************************************************************************/
  99. /*****************************************************************************/
  100.  
  101.  
  102.  
  103. static void    STGSContentClick(WindowPtr window, EventRecord *event, Boolean firstClick)
  104. {
  105. #pragma unused (firstClick)
  106.  
  107.     short            cnum;
  108.     ControlHandle    ctl;
  109.  
  110.     if (cnum = IsCtlEvent(window, event, &ctl, nil)) {
  111.         
  112.     }
  113. }
  114.  
  115.  
  116.  
  117. /*****************************************************************************/
  118.  
  119.  
  120.  
  121. static Boolean    STGSContentKey(WindowPtr window, EventRecord *event, Boolean *passThrough)
  122. {
  123. #pragma unused (passThrough)
  124.  
  125.     ControlHandle    ctl;
  126.     Str255            str;
  127.     WindowPtr        ww;
  128.     FileRecHndl        ff;
  129.     short            v;
  130.  
  131.     if (IsCtlEvent(window, event, nil, nil) == -1) {
  132.         ww = GetNextWindow(nil, kDocFileType);
  133.         if (ww) {
  134.             ff = (FileRecHndl)GetWRefCon(ww);
  135.             CNum2Ctl(window, 101, &ctl);
  136.             CTEGetPStr(ctl, str);
  137.             if (pcmp((*ff)->d.doc.testStr, str)) {
  138.                 (*ff)->d.doc.newImage = true;
  139.                 pcpy((*ff)->d.doc.testStr, str);
  140.             }
  141.             CNum2Ctl(window, 102, &ctl);
  142.             CTEGetPStr(ctl, str);
  143.             v = p2dec(str, nil);
  144.             if ((*ff)->d.doc.minSize != v) {
  145.                 (*ff)->d.doc.newImage = true;
  146.                 (*ff)->d.doc.minSize = p2dec(str, nil);
  147.             }
  148.             CNum2Ctl(window, 103, &ctl);
  149.             CTEGetPStr(ctl, str);
  150.             (*ff)->d.doc.maxSize = p2dec(str, nil);
  151.             BeginContent(ww);
  152.             DoImageDocument(ff);
  153.             EndContent(ww);
  154.             SetDocSize(ff, kwNoChange, (*ff)->d.doc.docSize);
  155.         }
  156.     }
  157.     return(true);
  158. }
  159.  
  160.  
  161.  
  162. /*****************************************************************************/
  163.  
  164.  
  165.  
  166. #pragma segment STGSPalette
  167. static OSErr    STGSImageDocument(FileRecHndl frHndl)
  168. {
  169. #pragma unused (frHndl)
  170.  
  171.     DoDrawControls((*frHndl)->fileState.window, false);
  172.     return(noErr);
  173. }
  174.  
  175.  
  176.  
  177. /*****************************************************************************/
  178.  
  179.  
  180.  
  181. #pragma segment STGSPalette
  182.  
  183. static Boolean    DigitFilter(TEHandle te, EventRecord *event, short *handled);
  184. static Boolean    DigitFilter(TEHandle te, EventRecord *event, short *handled)
  185. {
  186. #pragma unused (te, handled)
  187.  
  188.     char    key;
  189.     short    i;
  190.  
  191.     key = event->message   & charCodeMask;
  192.     i   = event->modifiers & keyCodeMask;
  193.     if (i & cmdKey)                    return(false);
  194.     if (i & optionKey)                return(false);
  195.     if (key == 8)                    return(false);
  196.     if (key == 9)                    return(false);
  197.     if ((key >= 28) && (key <= 31)) return(false);
  198.  
  199.     if ((key < '0') || (key > '9')) return(true);
  200.  
  201.     return(false);
  202. }
  203.  
  204. OSErr    STGSInitContent(FileRecHndl frHndl, WindowPtr window)
  205. {
  206.     OSErr            err;
  207.     ControlHandle    ctl;
  208.     short            i;
  209.  
  210.     err = AddControlSet(window, (*frHndl)->fileState.sfType, kwStandardVis, 0, 0, nil);
  211.     for (i = 102; i <= 103; ++i) {
  212.         CNum2Ctl(window, 102, &ctl);
  213.         if (ctl)
  214.             CTESetKeyFilter((TEHandle)GetCRefCon(ctl), DigitFilter);
  215.     }
  216.  
  217.     return(err);
  218. }
  219.  
  220.  
  221.  
  222.